﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.SYS.Library;
using ZX.DBModule;
using ZX.Common;
namespace ZX.SYS.Bussiness.Message
{
    public partial class BMessageItem : BLL.Extend.BaseBussnies<MessageItem>
    {
        public BMessageItem() { this.entity = new MessageItem(); }

        /// <summary>
        /// 获取所有系统的系统信息
        /// </summary>
        /// <returns>数据集</returns>
        public IList<MessageItem> GetSysMessages()
        {
            try
            {
                string s = "MessageType='0'";
                return this.GetEntityListByCondition<MessageItem>(s);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
       /// <summary>
        /// 获取指定用户的系统信息
       /// </summary>
       /// <param name="RowCount">设置显示的行数</param>
       /// <param name="ReceiverID">接收者编号</param>
       /// <returns></returns>
        public IList<MessageItem> GetReceiverSysMessages(int RowCount,string ReceiverID)
        {
            try
            {
                string s = "SELECT TOP " + RowCount + " [MPoolID] ,[MsgID] ,[Title] ,[MsgTemplate],[MsgContent],[MessageType],[ReceiverID],[Name],[AddUserName] ,[SendTime] FROM [V_MessagePool] where MessageType='0' and ReceiverID='" + ReceiverID + "'";
                return this.GetEntitysBySqlComm<MessageItem>(s);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取指定用户的系统信息
        /// </summary>
        /// <returns>数据集</returns>
        public IList<MessageItem> GetReceiverSysMessages(Guid ReceiverID)
        {
            try
            {
                string s = "MessageType='0' and ReceiverID='" + ReceiverID.ToString() + "'";
                return this.GetEntityListByCondition<MessageItem>(s);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取要发送Mail信息
        /// </summary>
        /// <returns>数据集</returns>
        public IList<MessageItem> GetMailMessages()
        {
            try
            {
                string s = "MessageType='1'";
                return this.GetEntityListByCondition<MessageItem>(s);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取要发送手机短信息
        /// </summary>
        /// <returns>数据集</returns>
        public IList<MessageItem> GetSMSMessages()
        {
            try
            {
                string s = "MessageType='2' ";
                return this.GetEntityListByCondition<MessageItem>(s);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取要发送QQ信息
        /// </summary>
        /// <returns>数据集</returns>
        public IList<MessageItem> GetQQMessages()
        {
            try
            {
                string s = "MessageType='3'";
                return this.GetEntityListByCondition<MessageItem>(s);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool MsgExists(Guid MsgID, Guid ReceiverID)
        {
            bool isExists = false;
            try
            {

                string s = " MsgID='" + MsgID.ToString() + "' and ReceiverID='" + ReceiverID.ToString()+ "'";
                MessageItem m = this.GetEntityByCondition<MessageItem>(s);
                if (m != null) { isExists = true; }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return isExists;
        }
        //where MsgID='' and ReceiverID='' and MessageType='0'
    }
}
